package com.fuhui.controller.service;


import com.fuhui.dao.txm.PadConfigMapper;
import com.fuhui.util.ReturnJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("padService")
public class SchoolPadConfigService {


    @Autowired
    private PadConfigMapper padMapper;

    /**
     * 根据学校ID获取配置列表
     * 参数：?schoolIds=1&name=1&type=1&status=1&isPage=0&pNum=1&pLine=10
     *Integer schoolIds,  String name , Integer type,  Integer status, Integer pNum,Integer pLine, Integer isPage
     * @return
     */
    @RequestMapping("getConfigListBySchoolId")
    public Object getConfigListBySchoolId(HttpServletRequest request){
        Map<String,Object> mapList = new HashMap<String, Object>();
        Map<String,Object> mapPage  = new HashMap<String, Object>();
        Integer isPage = Integer.parseInt(request.getParameter("isPage"));
        Integer schoolIds = Integer.parseInt(request.getParameter("schoolIds"));
        Integer type = Integer.parseInt(request.getParameter("type"));
        Integer status = Integer.parseInt(request.getParameter("status"));
        String name = request.getParameter("name");
        List list = null;
        if (isPage > 0 || isPage==1){
            Integer pNum = Integer.parseInt(request.getParameter("pNum"));
            Integer pLine = Integer.parseInt(request.getParameter("pLine"));
            list = padMapper.getList(schoolIds,name,type,status,pNum-1,pLine,isPage);
            mapPage.put("pageNum",pNum);
            mapPage.put("pageLine",pLine);
        }else {
            list = padMapper.getList(schoolIds,name,type,status,null,null,0);
            mapList.put("list",list);
            return ReturnJson.returnSuccessMap(mapList);
        }
        System.out.println("list=="+list);
        if (list == null || list.isEmpty()){
            return ReturnJson.returnList(list);
        }
        mapPage.put("countAll",list.size());
        System.out.println("page=="+mapPage);
        mapList.put("page",mapPage);
        mapList.put("list",list);
        return ReturnJson.returnSuccessMap(mapList);
    }


}
